package cn.wujiangbo.task;

import java.util.*;

/**
 * 下面是一个基于内容的推荐算法的简单实现示例。假设我们有一些电影，每个电影有一个类型属性，我们要根据用户的喜好进行推荐
 */
public class ContentBasedRecommendation {
    private Map<String, List<String>> movieFeatures;

    public ContentBasedRecommendation() {
        movieFeatures = new HashMap<>();
        movieFeatures.put("电影A", Arrays.asList("动作", "冒险"));
        movieFeatures.put("电影B", Arrays.asList("喜剧", "爱情"));
        movieFeatures.put("电影C", Arrays.asList("动作", "科幻"));
        movieFeatures.put("电影D", Arrays.asList("喜剧", "动画"));
        movieFeatures.put("电影E", Arrays.asList("科幻", "冒险"));
    }

    public List<String> recommendMovies(List<String> userLikes) {
        Map<String, Integer> movieScores = new HashMap<>();

        for (String movie : movieFeatures.keySet()) {
            int score = 0;
            List<String> features = movieFeatures.get(movie);

            for (String userLike : userLikes) {
                if (features.contains(userLike)) {
                    score++;
                }
            }

            movieScores.put(movie, score);
        }

        List<String> recommendedMovies = new ArrayList<>();

        for (String movie : movieScores.keySet()) {
            if (movieScores.get(movie) > 0) {
                recommendedMovies.add(movie);
            }
        }

        return recommendedMovies;
    }

    public static void main(String[] args) {
        ContentBasedRecommendation recommendation = new ContentBasedRecommendation();
        List<String> userLikes = Arrays.asList("喜剧", "爱情");

        List<String> recommendedMovies = recommendation.recommendMovies(userLikes);

        System.out.println("推荐的电影：");
        for (String movie : recommendedMovies) {
            System.out.println(movie);
        }
    }
}